unit unitadminpostulante;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
  maskedit, DbCtrls, sqldb, db, unitmainform, LR_Class, LR_Desgn;

type

  { TFormAdminPostulante }

  TFormAdminPostulante = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    ComboBox1: TComboBox;
    ComboBox2: TComboBox;
    Datasource1: TDatasource;
    DBComboBox1: TDBComboBox;
    Edit1: TEdit;
    Edit10: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Edit4: TEdit;
    Edit5: TEdit;
    Edit6: TEdit;
    Edit7: TEdit;
    Edit8: TEdit;
    Edit9: TEdit;
    frReport1: TfrReport;
    GroupBox1: TGroupBox;
    GroupBox2: TGroupBox;
    GroupBox3: TGroupBox;
    GroupBox4: TGroupBox;
    GroupBox5: TGroupBox;
    GroupBox6: TGroupBox;
    GroupBox7: TGroupBox;
    Label10: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    Label14: TLabel;
    Label15: TLabel;
    Label16: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    MaskEdit1: TMaskEdit;
    MaskEdit2: TMaskEdit;
    Memo1: TMemo;
    Memo2: TMemo;
    Memo3: TMemo;
    SQLQuery1: TSQLQuery;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure frReport1GetValue(const ParName: String; var ParValue: Variant);
  private
    { private declarations }
  public
    pst_nombre: string;
    edad: string;
    cdg: string;
  end;

var
  FormAdminPostulante: TFormAdminPostulante;

implementation

{$R *.lfm}

{ TFormAdminPostulante }

procedure TFormAdminPostulante.Button2Click(Sender: TObject);
begin
  Close();
end;

procedure TFormAdminPostulante.Button3Click(Sender: TObject);
begin
  frReport1.Clear;
  frReport1.LoadFromFile('postulante.lrf');
  frReport1.ShowReport;
end;

procedure TFormAdminPostulante.FormClose(Sender: TObject;
  var CloseAction: TCloseAction);
begin
  if SQLQuery1.Active = true then
    SQLQuery1.Close;

  Edit1.Text := '';
  Edit2.Text := '';
  Edit3.Text := '';
  Edit4.Text := '';
  Edit5.Text := '';
  Edit6.Text := '';
  Edit7.Text := '';
  Edit8.Text := '';
  Edit9.Text := '';
  Edit10.Text := '';

  ComboBox1.Text := '';
  ComboBox2.Text := '';

  Memo1.Text := '';
  Memo2.Text := '';
  Memo3.Text := '';

  cdg := '';
  pst_nombre := '';
  edad := '';
  Button3.Visible := false;
  Label11.Visible := false;
  MaskEdit1.Text := '';
  MaskEdit2.Text := '';
end;

procedure TFormAdminPostulante.Button1Click(Sender: TObject);
var
  QueryString: string;

begin
  if Button1.Caption = 'Guardar' then
    QueryString := 'insert into persona(prs_fecha_ingreso, prs_apellido, prs_nombre, prs_fecha_nacimiento, prs_dni, prs_domicilio, prs_estado_civil, prs_hijos, prs_telefono_fijo, prs_telefono_movil, '
      + 'prs_email, prs_facebook, prs_estudios, prs_estudios_comentario, prs_experiencia_laboral, prs_texto, prs_puesto, prs_caracteristicas_personales) values(''' + MaskEdit2.Text + ''', ''' + Edit1.Text
      + ''', ''' + Edit2.Text + ''', ''' + MaskEdit1.Text + ''', ''' + Edit3.Text + ''', ''' + Edit5.Text + ''', ''' + ComboBox1.Text + ''', ' + Edit4.Text + ', ''' + Edit6.Text
      + ''', ''' + Edit7.Text + ''', ''' + Edit8.Text + ''', ''' + Edit9.Text + ''', ''' + ComboBox2.Text + ''', ''' + Edit10.Text + ''', ''' + Memo1.Text + ''', ''' + Memo2.Text
      + ''', (select pst_cdg from puesto where pst_nombre = ''' + DBComboBox1.Text + '''), ''' + Memo3.Text + ''')'
  else
  if Button1.Caption = 'Modificar' then
    QueryString := 'update persona set prs_fecha_ingreso = ''' + MaskEdit2.Text + ''', prs_apellido = ''' + Edit1.Text + ''', prs_nombre = ''' + Edit2.Text + ''', prs_fecha_nacimiento = ''' + MaskEdit1.Text + ''', prs_dni = '''
      + Edit3.Text + ''', prs_domicilio = ''' + Edit5.Text + ''', prs_estado_civil = ''' + ComboBox1.text + ''', prs_hijos = ' + Edit4.Text + ', prs_telefono_fijo = ''' + Edit6.Text
      + ''', prs_telefono_movil = ''' + Edit7.Text + ''', prs_email = ''' + Edit8.Text + ''', prs_facebook = ''' + Edit9.Text + ''', prs_estudios = ''' + ComboBox2.Text
      + ''', prs_estudios_comentario = ''' + Edit10.Text + ''', prs_experiencia_laboral = ''' + Memo1.Text + ''', prs_texto = ''' + Memo2.Text
      + ''', prs_puesto = (select pst_cdg from puesto where pst_nombre = ''' + DBComboBox1.text + '''), prs_caracteristicas_personales = ''' + Memo3.Text + ''' where prs_cdg = '
      + cdg;

  MainForm.PQConnection1.ExecuteDirect('BEGIN WORK;');
  MainForm.PQConnection1.ExecuteDirect(QueryString);
  MainForm.PQConnection1.ExecuteDirect('COMMIT WORK;');

  ShowMessage('Operación Exitosa');

  Close();
end;

procedure TFormAdminPostulante.FormCreate(Sender: TObject);
begin
  SQLQuery1.DataBase := MainForm.PQConnection1;
  SQLQuery1.Transaction := MainForm.SQLTransaction1;
  pst_nombre := '';
end;

procedure TFormAdminPostulante.FormShow(Sender: TObject);
begin
  if SQLQuery1.Active = true then
    SQLQuery1.Close;

  SQLQuery1.SQL.Text := 'select pst_nombre from puesto order by pst_nombre';

  SQLQuery1.Open;

  DBComboBox1.Clear;

  DBComboBox1.DataField := 'pst_nombre' ;

  while not SQLQuery1.EOF do
  begin
    DBComboBox1.Items.Add(SQLQuery1.FieldByName('pst_nombre').AsString);
    SQLQuery1.Next;
  end;

  DBComboBox1.Text := pst_nombre;

  if Button1.Caption = 'Guardar' then
    MaskEdit2.Text := FormatDateTime('dd/mm/yyyy', Date);
end;

procedure TFormAdminPostulante.frReport1GetValue(const ParName: String;
  var ParValue: Variant);
begin
  if ParName = 'apellido' then
    ParValue := Edit1.Text;
  if ParName = 'nombre' then
    ParValue := Edit2.Text;
  if Parname = 'fecha_nacimiento' then
    ParValue := MaskEdit1.Text;
  if ParName = 'edad' then
    ParValue := edad;
  if Parname = 'dni' then
    ParValue := Edit3.Text;
  if ParName = 'estado_civil' then
    Parvalue := ComboBox1.text;
  if ParName = 'hijos' then
    ParValue := Edit4.Text;
  if ParName = 'fecha_ingreso' then
    ParValue := MaskEdit2.Text;
  if ParName = 'domicilio' then
    ParValue := Edit5.Text;
  if ParName = 'telefono_fijo' then
    ParValue := Edit6.Text;
  if ParName = 'telefono_movil' then
    ParValue := Edit7.Text;
  if ParName = 'email' then
    ParValue := Edit8.Text;
  if ParName = 'facebook' then
    ParValue := Edit9.Text;
  if ParName = 'estudios' then
    ParValue := ComboBox2.Text;
  if ParName = 'estudios_detalle' then
    ParValue := Edit10.Text;
  if ParName = 'experiencia_laboral' then
    ParValue := Memo1.Text;
  if ParName = 'texto' then
    ParValue := Memo2.Text;
  if ParName = 'caracteristicas_personales' then
    ParValue := Memo3.Text;
  if ParName = 'puesto' then
    ParValue := DBComboBox1.Text;
  if ParName = 'fecha_nacimiento' then
    ParValue := MaskEdit1.Text;
end;

end.

